home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / program / snpd9611.zip / PI.C < prev    next >
Text File  |  1996-11-24  |  2KB  |  62 lines

  1. .I 0 2
  2. /* +++Date last modified: 24-Sep-1996 */
  3.  
  4. .I 3 25
  5. **  Uses far arrays when/where required so may be compiled in any memory model
  6. **
  7. **  The formula that most use (including the one in the Snippets) is the
  8. **  classic Machin formula, with the Gregory series.
  9. **  
  10. **  pi=16arctan(1/5)-4arctan(1/239)
  11. **  
  12. **  And use the traditional Gregory arctangent series to calculate the
  13. **  arctangents. That's the:
  14. **  
  15. **  arctan(x)=x-(x^3)/3+(x^5)/5-(x^7)/7.....
  16. **  
  17. **  With 1/5 and 1/239, it would be:
  18. **  
  19. **  arctan(x)=1/5-1/(3*5^3)+1/(5*5^5)-1/(7*5^7)...
  20. **  arctan(x)=1/239-1/(3*239^3)+1/(5*239^5)-1/(7*239^7)....
  21. **  
  22. **  Doing the multi-precision isn't too hard, since we don't really need to
  23. **  have a general purpose math package.  We can hardwire it all.
  24. **
  25. **  Due to the % operator, ms[i] < (temp * (239**2)) so
  26. **  temp < 3759 and i < 1879, it fails at the 1879th term which translates to
  27. **  1879 * log10(239**2) == 8941th decimal.
  28. **
  29. **  In practice we get a few more digits, (2 -> 8943th)
  30. .D 4 1
  31. .I 13 5
  32. long i, line;
  33. long col, col1;
  34. long loc, FAR stor[4096];
  35.  
  36. static void PASCAL shift(long FAR *l1, long FAR *l2, long lp, long lmod)
  37. .D 14 5
  38. .I 26 1
  39. static void PASCAL yprint(long m)
  40. .D 27 1
  41. .I 33 1
  42.                   if (++col1 == 5)
  43. .D 34 1
  44. .I 36 1
  45.                         printf("\nL%04ld:", ++line);
  46. .D 37 1
  47. .I 46 1
  48. static void PASCAL xprint(long m)
  49. .D 47 1
  50. .I 73 1
  51. static void PASCAL memerr(int errno)
  52. .D 74 1
  53. .I 94 1
  54.       if (NULL == mf)
  55. .D 95 1
  56. .I 97 1
  57.       if (NULL == ms)
  58. .D 98 1
  59. .I 114 1
  60.       printf("\nL%04ld: 3.", ++line);
  61. .D 115 1
  62.